package com.wnxy.eleba.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wnxy.eleba.entity.Rider;
import com.wnxy.eleba.mapper.RiderMapper;
import com.wnxy.eleba.service.RiderService_wzj;
import com.wnxy.eleba.vo.RiderQueryParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class RiderServiceImpl_wzj implements RiderService_wzj {

    private RiderMapper riderMapper;

    @Autowired
    public void setRiderMapper(RiderMapper riderMapper) {
        this.riderMapper = riderMapper;
    }

    @Override
    public PageInfo<Rider> listRider(Integer pageNum, Integer pageSize, Rider Rider) {
        PageHelper.startPage(pageNum,pageSize);
        List<com.wnxy.eleba.entity.Rider> list = riderMapper.findByCondition(Rider);
        PageInfo<com.wnxy.eleba.entity.Rider> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Rider> listPageRider(RiderQueryParam riderQueryParam) {
        PageHelper.startPage(riderQueryParam.getCurrentPage(),riderQueryParam.getPageSize());
        List<Rider> rideList = riderMapper.selectRiderByCondition(riderQueryParam);
        PageInfo<Rider> pageInfo = new PageInfo<>(rideList);
        return pageInfo;
    }

    @Override
    public Rider findRider(Rider Rider) {
        List<com.wnxy.eleba.entity.Rider> list = riderMapper.findAllByRiderNameAndRiderPassword(Rider.getRiderName(), Rider.getRiderPassword());
//        Rider Rider1 = RiderMapper.selectByNameAndPwd(Rider.getName(),Rider.getPassword());
//        System.out.println(Rider1.toString());

        return list.size()==1?list.get(0):null;
    }

    @Override
    public boolean addRider(Rider Rider) {
        return riderMapper.insert(Rider)!=0;
    }

    @Override
    public Rider findRiderById(Integer riderId) {

        return riderMapper.selectByPrimaryKey(riderId);
    }

    @Override
    public boolean delriders(Integer[] ids) {
        int result = riderMapper.deleteByIds(ids);
        return result==ids.length;
    }

    @Override
    public boolean updateRider(Rider rider) {

        int result = riderMapper.updateByPrimaryKey(rider);
        return result==1;
    }
}
